<template>
  <div>
    <Headline
      :headline1="$t('m.EquipmentCenter') + '  /  '"
      :headline2="$t('m.CardOperation')"
    ></Headline>
    <a-card style="width: 100%">
      <span class="menus-title">{{
        $t("m.Choosedepartment")
      }}：</span>
      <!-- <select-tree @checkData="argumentSelect"> </select-tree> -->
       <a-tree-select
          v-model="treedefalue"
          show-search
          style="width: 200px; height: 40px;"
          :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
          placeholder="Please select"
          @change="argumentSelect"
          tree-default-expand-all
        >

          <a-tree-select-node
            v-for="item in departmentListA"
            :key="item.id"
            :cont="item"
            :value="item.custorgname"
            :title="item.custorgname"
          >
            <a-tree-select-node
              v-for="int in item.children"
              :key="int.id"
              :cont="int"
              :value="int.custorgname"
              :title="int.custorgname"
            >
              <a-tree-select-node
                v-for="ins in int.children"
                :key="ins.id"
                :cont="ins"
                :value="ins.custorgname"
                :title="ins.custorgname"
              />
            </a-tree-select-node>
          </a-tree-select-node>
        </a-tree-select>
      <a-input-search
        style="
          width: 310px;
          margin-bottom: 30px;
          margin-left: 15px;
          margin-right: 15px;
        "
        :placeholder="$t('m.PleaseEnterYourSearchTerms')"
        :enter-button="$t('m.Inquire')"
        size="default"
        v-model="staffKey"
        @search="personInfoSearch"
      />
      <a-table
        :rowKey="(record) => record.id"
        :data-source="data"
        :columns="columns"
        :pagination="false"
        bordered
      >
        <div slot="tags" slot-scope="text, tags, i">
          <a-button type="primary" @click="moreInfo(text, tags, i)">{{
            $t("m.detailedInformation")
          }}</a-button>
        </div>
      </a-table>
      <a-pagination
        style="margin-top: 15px"
        show-size-changer
        :default-current="1"
        :total="total"
        @change="PagesA"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="onShowSizeChangeA"
        class="pages"
      />
    </a-card>
    <Drawer ref="changed">
      <a-select
        default-value="全部"
        style="width: 120px; margin-bottom: 20px"
        @change="selectChange"
      >
        <a-select-option
          :value="item.code"
          :key="item.code"
          v-for="item in dictionariesB"
        >
          {{ item.name }}
        </a-select-option>
      </a-select>
      <a-input-search
        style="
          width: 310px;
          margin-bottom: 30px;
          margin-left: 15px;
          margin-right: 15px;
        "
        :placeholder="$t('m.Cardnumberquery')"
        :enter-button="$t('m.Inquire')"
        size="default"
        v-model="cardNum"
        @search="cardNumSearch"
      />
      <a-dropdown>
        <a-button type="primary" icon="unordered-list">
          {{ $t("m.More") }}
        </a-button>
        <a-menu slot="overlay">
          <a-menu-item @click="SendCard">
            <a href="javascript:;" v-if="isTrue('card:ctrl:add')">{{
              $t("m.SendCard")
            }}</a>
            <a-modal
              width="900px"
              :title="$t('m.cardInformation')"
              :visible="sendCardShow"
              @ok="sendCardOk"
              @cancel="sendCardCancel"
              :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"
            >
              {{ $t("m.Name")
              }}：<a-input
                v-model="itemInfo.stafforstuname"
                disabled
                style="width: 150px; margin-right: 50px"
              />
              {{ $t("m.cardholder")
              }}：<a-select
              v-model="cardHolder"
                :default-value="$t('m.Self')"
                style="width: 150px"
                @change="cardholderType"
              >
                <a-select-option
                  v-for="item in dictionariesA"
                  :value="item.code"
                  :key="item.code"
                  >{{ item.name }}</a-select-option
                >
              </a-select>
              <a-table
                :rowKey="(record) => record.id"
                style="margin-top: 20px; margin-bottom: 20px"
                :data-source="dataC"
                :columns="columnsC"
                :pagination="false"
                :row-selection="{ onChange: onSelectChange, type: radio }"
                bordered
              />
              {{ $t("m.CardNumber")
              }}：<a-input
                v-model="existsCardparameter.cardNo"
                style="width: 150px; margin-right: 50px"
              />
              {{ $t("m.periodofvalidity") }}：

              <a-date-picker placeholder="Select Time"
              :default-value="defdata"
               @change="dataOpenChange" />
              <br />
              {{ $t("m.remark")
              }}：<a-input
                v-model="existsCardparameter.des"
                style="width: 719px; margin-top: 20px"
              />
            </a-modal>
          </a-menu-item>
          <a-menu-item @click="LossCard">
            <a href="javascript:;" v-if="isTrue('card:ctrl:loss')">{{
              $t("m.reportthelossof")
            }}</a>
            <a-modal
              width="900px"
              :title="$t('m.reportthelossof')"
              :visible="lossCardShow"
              @ok="lossCardOk"
              @cancel="lossCardCancel"
              :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"
            >
              {{ $t("m.personalInformation")
              }}：<input
                :placeholder="$t('m.pleaseChoose')"
                style="margin-bottom: 10px;"
                v-model="selectKey"
                ref="inputsele"
                @click="inputFocus"
                type="text"
                class="tableInput"
              />
              <!-- <div v-show="tableShow" style=""></div> -->
              <a-table
                bordered
                :rowKey="(record) => record.id"
                style="margin-bottom: 20px"
                :data-source="dataE"
                :columns="columnsE"
                size="small"
                :pagination="false"
                :row-selection="{ onChange: onSelectChangeE, type: radio }"
              />
              {{ $t("m.remark") }}：
              <a-input style="width: 719px;" v-model="forminitialE.des"></a-input>
            </a-modal>
          </a-menu-item>
          <a-menu-item @click="repairCard">
            <a href="javascript:;" v-if="isTrue('card:ctrl:repair')">{{
              $t("m.ReissueCard")
            }}</a>
            <a-modal
              width="900px"
              :title="$t('m.ReissueCard')"
              :visible="repairCardShow"
              @ok="repairCardOk"
              @cancel="repairCardCancel"
              :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"

            >
              {{ $t("m.Name")
              }}：<a-input
                v-model="itemInfo.stafforstuname"
                disabled
                style="width: 150px; margin-right: 50px"
              />
              {{ $t("m.Learntoworknumber")
              }}：<a-input
                v-model="itemInfo.ymorgtreecode"
                disabled
                style="width: 150px; margin-right: 50px"
              />
              <a-table
                :rowKey="(record) => record.id"
                style="margin-top: 20px; margin-bottom: 20px"
                :data-source="dataC"
                :columns="columnsC"
                :row-selection="{ onChange: onSelectChange, type: radio }"
                :pagination="false"
                bordered
              />
              {{ $t("m.CardNumber")
              }}：<a-input
                v-model="existsCardparameter.cardNo"
                style="width: 150px; margin-right: 50px"
              />
              {{ $t("m.periodofvalidity") }}：
              <a-date-picker
                format="YYYY-MM-DD"
                v-model="existsCardparameter.indate"
                @change="dataOpenChange"
                style="margin-right: 50px"
              />
              <br />
              {{ $t("m.remark")
              }}：<a-input
                v-model="existsCardparameter.des"
                style="width: 719px; margin-top: 20px"
              />
            </a-modal>
          </a-menu-item>
          <a-menu-item @click="quitCard">
            <a href="javascript:;" v-if="isTrue('card:ctrl:return')">{{
              $t("m.returnthecard")
            }}</a>
            <a-modal
              width="900px"
              :title="$t('m.returnthecard')"
              :visible="quitCardShow"
              @ok="quitCardOk"
              @cancel="quitCardCancel"
              :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"
            >
              {{ $t("m.CardNumber")
              }}：<a-input
                v-model="itemInfo.cardno"
                disabled
                style="width: 100px; margin-right: 50px;"
              />
              {{ $t("m.periodofvalidity")
              }}：<a-input disabled v-model="defendata" style="width: 100px; margin-right: 50px" />

              {{ $t("m.CardCost")
              }}：<a-input
                default-value="0"
                disabled
                style="width: 100px; margin-right: 50px;"
              />
              <a-table
                :rowKey="(record) => record.id"
                style="margin-top: 30px; margin-bottom: 15px"
                :data-source="dataC"
                :columns="columnsC"
                :pagination="false"
                bordered
                :row-selection="{ onChange: onSelectChange, type: radio }"
              />
              {{$t('m.BusinessCardPrintingFeeIsReturned')}}：
              <a-radio-group v-model="quitOrValue" @change="quitOrChange">
                <a-radio :value="1"> {{$t('m.refunds')}} </a-radio>
                <a-radio :value="2"> {{$t('m.Norefunds')}} </a-radio>
              </a-radio-group>
              {{ $t("m.remark")
              }}：<a-input
                v-model="quitList.des"
                style="width: 300px; margin-right: 50px"
              />
            </a-modal>
          </a-menu-item>
          <a-menu-item @click="postpone">
            <a href="javascript:;" v-if="isTrue('card:ctrl:delay')">{{
              $t("m.postpone")
            }}</a>
            <a-modal
              width="900px"
              :title="$t('m.postpone')"
              :visible="postponeCardShow"
              @ok="postponeCardOk"
              @cancel="postponeCardCancel"
              :cancelText="$t('m.Cancel')"
    :okText="$t('m.Ok')"
            >
              {{ $t("m.Name")
              }}：<a-input
                v-model="itemInfo.stafforstuname"
                disabled
                style="width: 150px; margin-right: 50px"
              />
              {{ $t("m.Learntoworknumber")
              }}：<a-input
                v-model="itemInfo.ymorgtreecode"
                disabled
                style="width: 150px; margin-right: 50px"
              />
              <a-table
                :rowKey="(record) => record.id"
                style="margin-top: 20px; margin-bottom: 20px"
                :data-source="dataC"
                :columns="columnsC"
                :pagination="false"
                bordered
                :row-selection="{ onChange: onSelectChange, type: radio }"
              />

              {{ $t("m.ValidUntil") }}：
              <a-date-picker
              v-model="existsCardparameter.indate"
              format="YYYY-MM-DD"
              @change="dataOpenChangeB" />
            </a-modal>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
      <a-modal
        :title="$t('m.SelectPersonnel')"
        width="600px"
        :visible="visibleG"
        @ok="handleOkG"
        @cancel="handleCancelG"
        :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"
      >
      <a-input-search :placeholder="$t('m.PleaseEnterYourSearchTerms')"
      v-model="forminitialD.key"
      style="width:200px;margin-right:15px;" enter-button @search="onSearchK" />
      <select-tree @checkData="argumentSelectA"> </select-tree>
        <a-table
          bordered
          :rowKey="(record) => record.id"
          style="margin-bottom: 20px;margin-top:20px;"
          :data-source="dataD"
          :columns="columnsD"
          size="small"
          :pagination="false"
          :row-selection="{ onChange: onSelectChangeD, type: radio }"
        />
        <a-pagination
          style="margin-top: 20px"
          show-size-changer
          :default-current="1"
          :total="totalD"
          @change="PagesD"
          :pageSizeOptions="['5', '10', '30', '40']"
          @showSizeChange="onShowSizeChangeD"
          class="pages"
        />
      </a-modal>
      <a-table
        :rowKey="(record) => record.id"
        :data-source="dataB"
        :columns="columnsB"
        :pagination="false"
        bordered
      />
      <a-pagination
        style="margin-top: 20px"
        show-size-changer
        :default-current="1"
        :total="totalB"
        @change="PagesB"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="onShowSizeChangeB"
        class="pages"
      />
    </Drawer>
  </div>
</template>

<script>
// import {moment} from '../../../assets/js/moment.js'
import Headline from "@/components/Headline";
import Drawer from "@/components/Drawer";
import SelectTree from "@/components/common/SelectTree";
import { getdiction } from "@/api/dictionaries";
import { mapMutations } from "vuex";
import {
  getPerages,
  getPersonInfo,
  getCartOpera,
  getAlreadyInfo,
  existsCard,
  sendCardOrRepair,
  saveDelayCard,
  quitCard,
  lossCard,
} from "@/api/keraStase";
import { Setperms } from "@/assets/js/setperms";

export default {
  name: "Percard",
  components: { Headline, Drawer, SelectTree },
  data() {
    return {
      demoexistsCardparameter:'',
      defalutDate:null,
      visibleG: false,
      fromdic: {
        groupcode: "SYS0000005",
        // insertall: "-1|全部",
        where: "code<> -1 and code <> -100",
      },
      fromdicB: {
        groupcode: "SYS0000006",
        insertall: "-1|全部",
        where: "code<> -1 and code <> -100",
      },
      dictionariesA: [],
      dictionariesB: [],
      value: "",
      departmentList: [], //部门组织结构列表
      staffKey: "", //员工信息关键字
      columns: [
        {
          title: this.$t("m.jobnumber"),
          dataIndex: "stafforstucode",
        },
        {
          title: this.$t("m.Name"),
          dataIndex: "stafforstuname",
        },
        {
          title: this.$t("m.CardNumber"),
          dataIndex: "cardno",
        },
        {
          title: this.$t("m.AffiliatedUnit"),
          dataIndex: "orgname",
        },
        {
          title: this.$t("m.Operation"),
          dataIndex: "tags",
          key: "tags",
          scopedSlots: { customRender: "tags" },
        },
      ],
      columnsB: [
        {
          title: this.$t("m.Operation"),
          dataIndex: "dotype",
        },
        {
          title: this.$t("m.CardNumber"),
          dataIndex: "cardno",
        },
        {
          title: this.$t("m.cardholder"),
          dataIndex: "currholder",
        },
        {
          title: this.$t("m.OperatingPersonnel"),
          dataIndex: "creator",
        },
        {
          title: this.$t("m.OperatingTime"),
          dataIndex: "createdate",
        },
        {
          title: this.$t("m.remark"),
          dataIndex: "des",
        },
      ],
      columnsC: [
        {
          title: this.$t("m.Type"),
          dataIndex: "ismain",
        },
        {
          title: this.$t("m.CardNumber"),
          dataIndex: "cardno",
        },
        {
          title: this.$t("m.cardholder"),
          dataIndex: "currholder",
        },
        {
          title: this.$t("m.CardCost"),
          dataIndex: "deposit",
        },
        {
          title: this.$t("m.Status"),
          dataIndex: "status",
          customRender:function (text){
              if(text=='0'){
                return "无效";
              }else if(text=='1'){
                return "正常";
              } else {
                return '挂失'
              }
            }

        },
        {
          title: this.$t("m.TheIssuingTime"),
          dataIndex: "createdate",
        },
        {
          title: this.$t("m.periodofvalidity"),
          dataIndex: "enddate",
        },
        {
          title: this.$t("m.remark"),
          dataIndex: "des",
        },
      ],
      data: [],
      dataB: [],
      dataC: [],
      defaultValue: "",
      defalutTree: "云麦科技",
      forminitial: {
        ymOrgTreeCode: "",
        infoType: 1,
        status: 1,
        vChild: true,
        key: "",
        limit: 10, //每页展示多少条
        page: 1, //展示第几页
        start: 0, //数据截取
      },
      forminitialb: {
        staffOrStudInfoId: '',
        doType: -1,
        start: 0,
        limit: 10,
        page: 1,
        startDate: "",
        endDate: "",
        des: "",
        key: "",
      },
      total: null,
      totalB: null,
      cardNum: "",
      sendCardShow: false,
      itemInfo: {},
      selectedRows: {},
      dateTime: "",
      //验证是否可以 发卡 补卡参数
      existsCardparameter: {
        id: 0,
        cardNo: "",
        staffOrStudInfoId: "",
        isMain: "1",
        status: 1,
        indate:'2050-01-01',
        currHolder:0,
      },
      lossCardShow: false,
      repairCardShow: false,
      postponeCardShow: false,
      demo: "",
      radio: "radio",
      timeOut: "",
      // 卡延期参数{}
      postponeList: {
        cardIds: "",
        staffOrStudInfoId: "",
        isMain: "",
        endDate: "",
        staffOrStudInfoId: "",
        staffOrStuCode: "",
        staffOrStuName: "",
        des: "",
      },
      quitCardShow: false,
      cardHolder:'本人',
      quitOrValue: 2,
      defendata:"",
      // 退卡参数
      quitList: {
        id: "",
        currHolder: "0",
        cardNo: "",
        isMain: "",
        staffOrStudInfoId: "",
        des: "",
        deposit:0,
        isdeposit:false,
        status:''
      },
      tableShow: false,
      isYanqi:'',
      columnsD: [
        {
          title: this.$t("m.jobnumber"),
          dataIndex: "stafforstucode",
        },
        {
          title: this.$t("m.Name"),
          dataIndex: "stafforstuname",
        },
        {
          title: this.$t("m.Sex"),
          dataIndex: "sex",
        },
        {
          title: this.$t("m.PersonnelType"),
          dataIndex: "infotype",
        },
        {
          title: this.$t("m.department"),
          dataIndex: "orgname",
        },
      ],
      // columnsE:[],
      defdata:this.$moment('2050-01-01','YYYY-MM-DD'),
      columnsE: [
        {
          title: this.$t("m.Type"),
          dataIndex: "ismain",
          customRender:function (text){
              if(text=='0'){
                return "子卡";
              }else{
                return "主卡";
              }
            }
        },
        {
          title: this.$t("m.CardNumber"),
          dataIndex: "cardno",
        },
        {
          title: this.$t("m.cardholder"),
          dataIndex: "currholder",
          customRender:function (text){
              if(text=='0'){
                return "本人";
              }else if (text == '1'){
                return "父亲";
              }
              else if (text == '2'){
                return "母亲";
              }
              else if (text == '3'){
                return "朋友";
              }
              else if (text == '4'){
                return "兄妹";
              } else {
                return '其他关系'
              }
            }
        },
        {
          title: this.$t("m.CardCost"),
          dataIndex: "deposit",
        },
        {
          title: this.$t("m.Status"),
          dataIndex: "status",
          customRender:function (text){
              if(text=='0'){
                return "无效";
              }else{
                return "有效";
              }
          }
        },
        {
          title: this.$t("m.TheIssuingTime"),
          dataIndex: "createdate",
        },
        {
          title: this.$t("m.periodofvalidity"),
          dataIndex: "enddates",
        },
        {
          title: this.$t("m.remark"),
          dataIndex: "des",
        },
      ],

      dataD: [],
      totalD: 0,
      forminitialD: {
        ymOrgTreeCode: "",
        infoType: 0,
        status: -1,
        limit: 10, //每页展示多少条
        page: 1, //展示第几页
        start: 0, //数据截取
        key:"",
      },
      radio: "radio",
      selectKey: "",
      staffOrStudInfoIdD: "",
      dataE: [],
      // 挂卡解卡请求参数
      forminitialE: {
        id: "",
        staffOrStudInfoId: "",
        cardNo: "",
        isMain: "",
        des: "",
        cardId: "",
      },
      deselectName:'',
      treedefalue:'',
      departmentListA:[]
    };
  },
  computed: {},
  created() {
    // 请求组织结构数据
    this.onSearch();
    this.personInfo(this.forminitial);
    this._getdiction();
    this.parms = Setperms(
      this.$route.fullPath,
      JSON.parse(sessionStorage.getItem("menu"))
    );
    getPerages({params:{orgType:1}})
    .then(res => {
      this.departmentListA = res.data
      this.forminitial.ymOrgTreeCode = res.data[0].ymorgtreecode
      console.log(res.data)
      this.treedefalue = res.data[0].custorgname
    })
    .catch(err => {
      console.log(err)
    })
  },
  methods: {
    onSearchK(){
      this.personInfoB(this.forminitialD);
    },
    handleOkG() {
      this.selectKey = this.deselectName
      getAlreadyInfo({ params: { staffOrStudInfoId: this.staffOrStudInfoIdD } })
        .then((res) => {
          this.dataE = res.data.data;
          console.log(res.data.data);
        })
        .catch((err) => {
          console.log(err);
        });
      this.visibleG = false
    },
    handleCancelG() {

      this.visibleG = false;
    },
    isTrue(str) {
      return this.parms.indexOf(str) !== -1;
    },
    _getdiction() {
      getdiction({ params: this.fromdic }).then((res) => {
        console.log(res);
        this.dictionariesA = res.data.data;
      });
      getdiction({ params: this.fromdicB }).then((res) => {
        console.log(res);
        this.dictionariesB = res.data.data;
      });
    },
    ...mapMutations(["setDefaultValue"]),

    // 挂失/解挂
    PagesD(page, pageSize) {
      this.tableShow = true;
      this.forminitialD.limit = pageSize;
      this.forminitialD.page = page;
      this.forminitialD.start = (page - 1) * pageSize;
      this.personInfoB(this.forminitialD);
    },
    closeBtn() {
      this.tableShow = false;
    },
    onShowSizeChangeD(page, limit) {
      this.tableShow = true;
      this.forminitialD.page = page;
      this.forminitialD.limit = limit;
      this.personInfoB(this.forminitialD);
    },
    onSelectChangeE(selectedRowKeys, selectedRows) {
      this.forminitialE.id = selectedRows[0].id;
      this.forminitialE.staffOrStudInfoId = selectedRows[0].stafforstudinfoid;
      this.forminitialE.cardNo = selectedRows[0].cardno;
      this.forminitialE.isMain = selectedRows[0].ismain;
      this.forminitialE.cardId = selectedRows[0].id;
      this.forminitialE.status = selectedRows[0].status;
      this.forminitialE.currHolder = selectedRows[0].currholder;
    },
    onSelectChangeD(selectedRowKeys, selectedRows) {
      this.deselectName = selectedRows[0].stafforstuname;
      this.staffOrStudInfoIdD = selectedRows[0].id;
      console.log(selectedRows[0])

      this.tableShow = false;
    },
    personInfoB(params) {
      getPersonInfo({ params })
        .then((res) => {
          this.totalD = res.data.total;
          res.data.data.forEach((item) => {
            if (item.sex == 1) {
              item.sex = "男";
            }
            if (item.sex == 2) {
              item.sex = "女";
            }
            if (item.infotype == 1) {
              item.infotype = "职工";
            }
            if (item.infotype == 2) {
              item.infotype = "学生";
            }
          });
          this.dataD = res.data.data;
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // input获得焦点
    inputFocus() {
      this.visibleG = true;
      this.personInfoB(this.forminitialD);
    },
    // 补卡
    repairCard() {
      this.repairCardShow = true;
      this.getAlreadyInfoList();
    },
    repairCardOk() {
      if (this.existsCardparameter.id == "") {
        this.$message.error("请选择有效的卡片");
        return;
      }
      if (this.existsCardparameter.cardNo == "") {
        this.$message.error("请输入卡号");
        return;
      }
      this.demoexistsCardparameter = this.existsCardparameter.cardNo
      existsCard(this.existsCardparameter)
        .then((res) => {
          console.log(res);
          if (res.data.success == true) {
            // this.$message.success("补卡成功");
            // this.getCartOperaList(this.forminitialb);
            // this.handleOkG()
            //  this.personInfoB(this.forminitialD)
            console.log(this.demoexistsCardparameter)
            this.existsCardparameter.cardNo = this.demoexistsCardparameter
            sendCardOrRepair(this.existsCardparameter)
            .then((res) => {
                this.$message.success(res.data.msg);
                this.existsCardparameter.indate = '2050-01-01'
                this.getCartOperaList(this.forminitialb);
                this.personInfoB(this.forminitialD)

              })
              .catch((err) => {
                this.$message.error("发卡失败");
              });
          }
          if (res.data.success == false) {
            this.$message.error(res.data.msg);
          }
        })
        .catch((err) => {
          // console.log(err)
          this.$message("操作失败");
        });
        this.existsCardparameter.indate = '2050-01-01'
      this.quitList.id = "";
      this.existsCardparameter.cardNo = "";
      this.repairCardShow = false;
    },
    repairCardCancel() {
      this.quitList.id = "";
      this.existsCardparameter.cardNo = "";
      this.repairCardShow = false;
      this.existsCardparameter.indate = '2050-01-01'
    },
    // 退还还是不退还
    quitOrChange(e) {

      console.log(e.target.value)
      if(e.target.value == 1) {
        this.quitList.isdeposit = true
      } else {
        this.quitList.isdeposit = false
      }
    },
    // 退卡
    quitCard() {
      this.quitCardShow = true;
      this.getAlreadyInfoList();
    },
    quitCardOk() {
      if (this.quitList.id == "") {
        this.$message.error("请选择有效的卡片");
        return;
      }
      quitCard(this.quitList)
        .then((res) => {
          console.log(res);
          if (res.data.success == false) {
            this.$message.error(res.data.msg);
          }
          if (res.data.success == true) {
            this.$message.success(res.data.msg);
            this.getCartOperaList(this.forminitialb);
                this.personInfoB(this.forminitialD)
          }
        })
        .catch((err) => {
          console.log(err);
          this.$message.error("操作失败");
        });
      this.quitList.id == "";
      this.quitCardShow = false;
    },
    quitCardCancel() {
      this.quitList.id == "";
      this.quitCardShow = false;
    },
    // 选择表格二的一条数据
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log(selectedRows);
      this.quitList.status = selectedRows[0].status
      // this.existsCardparameter.id = ;
      // 补卡/发卡
      this.existsCardparameter.id = selectedRows[0].id;
      this.existsCardparameter.staffOrStudInfoId = this.itemInfo.id;
      if (selectedRows[0].ismain == "主卡") {
        this.existsCardparameter.isMain = 1;
      }
      if (selectedRows[0].ismain == "子卡") {
        this.existsCardparameter.isMain = 0;
      }
      this.existsCardparameter.status = selectedRows[0].status;
      // if (selectedRows[0].status == "无效") {
      //   this.existsCardparameter.status = 0;
      // }
      // if (selectedRows[0].status == "正常") {
      //   this.existsCardparameter.status = 1;
      // }
      // if (selectedRows[0].status == "挂失") {
      //   this.existsCardparameter.status = 2;
      // }

      // 退卡
      this.quitList.id = selectedRows[0].id;
      if (selectedRows[0].currholder == "本人") {
        this.quitList.currHolder = 0;
      }
      if (selectedRows[0].currholder == "父亲") {
        this.quitList.currHolder = 1;
      }
      if (selectedRows[0].currholder == "母亲") {
        this.quitList.currHolder = 2;
      }
      if (selectedRows[0].currholder == "朋友") {
        this.quitList.currHolder = 3;
      }
      if (selectedRows[0].currholder == "兄妹") {
        this.quitList.currHolder = 4;
      }
      if (selectedRows[0].currholder == "其他关系") {
        this.quitList.currHolder = 5;
      }
      this.quitList.cardNo = selectedRows[0].cardno;
      if (selectedRows[0].ismain == "主卡") {
        this.quitList.isMain = 1;
      }
      if (selectedRows[0].ismain == "子卡") {
        this.quitList.isMain = 0;
      }
      this.quitList.staffOrStudInfoId = this.itemInfo.id;
      // 卡延期
      this.postponeList.cardIds = selectedRows[0].id;
      this.isYanqi = selectedRows[0].status

      this.postponeList.staffOrStudInfoId = this.itemInfo.id;
      if (selectedRows[0].ismain == "主卡") {
        this.postponeList.isMain = 1;
      }
      if (selectedRows[0].ismain == "子卡") {
        this.postponeList.isMain = 0;
      }
      this.postponeList.endDate = this.$moment(this.timeOut._d).format(
        "YYYY-MM-DD"
      );
      this.postponeList.staffOrStuCode = this.itemInfo.stafforstucode;
      this.postponeList.staffOrStuName = this.itemInfo.stafforstuname;
      this.postponeList.des = selectedRows[0].des;
      // console.log(this.postponeList)
    },

    getAlreadyInfoList() {
      getAlreadyInfo({
        params: { staffOrStudInfoId: this.forminitialb.staffOrStudInfoId },
      })
        .then((res) => {
          // console.log(res.data.data)
          let dataList = res.data.data;
          this.defendata = res.data.data[0].enddate
          console.log(dataList);
          dataList.forEach((item) => {
            if (item.ismain == 0) {
              item.ismain = "子卡";
            }
            if (item.ismain == 1) {
              item.ismain = "主卡";
            }
            if (item.currholder == 0) {
              item.currholder = "本人";
            }
            if (item.currholder == 1) {
              item.currholder = "父亲";
            }
            if (item.currholder == 2) {
              item.currholder = "母亲";
            }
            if (item.currholder == 3) {
              item.currholder = "朋友";
            }
            if (item.currholder == 4) {
              item.currholder = "兄妹";
            }
            if (item.currholder == 5) {
              item.currholder = "其他关系";
            }
            // if (item.status == 0) {
            //   item.status = "无效";
            // }
            // if (item.status == 1) {
            //   item.status = "正常";
            // }
            // if (item.status == 2) {
            //   item.status = "挂失";
            // }
            item.createdate = this.$moment(item.createdate).format(
              "YYYY/MM/DD hh:mm:ss"
            );
            item.enddate = this.$moment(item.enddate).format(
              "YYYY/MM/DD hh:mm:ss"
            );
          });
          this.dataC = res.data.data;
          console.log(this.dataC)
        })
        .catch((err) => {
          console.log(err);
          this.$message.error("获取数据失败");
        });
    },
    dataOpenChangeB(e) {
      this.postponeList.endDate = this.$moment(e._d).format('YYYY-MM-DD')
      console.log(e)
    },
    // 延期
    postpone() {
      this.postponeCardShow = true;
      this.getAlreadyInfoList();
    },
    postponeCardOk() {
      if (this.postponeList.cardIds == "") {
        this.$message.error("请勾选需要延期到有效卡片");
        return;
      }
      console.log(this.isYanqi)
      if(this.isYanqi == 2) return this.$message.warning('该卡已挂失，无法延期')
      saveDelayCard(this.postponeList)
        .then((res) => {
          // console.log(res)
          if (res.data.success == false) {
            this.$message.error(res.data.msg);
          }
          if (res.data.success == true) {
            this.getCartOperaList(this.forminitialb);
            this.$message.success("操作成功");
          }
        })
        .catch((err) => {
          // console.log(err)
          this.$message.error("操作失败");
        });
        this.existsCardparameter.indate = '2050-01-01'
      this.postponeList.cardIds == "";
      this.timeOut = "";
      this.postponeCardShow = false;
    },
    postponeCardCancel() {
      this.existsCardparameter.indate = '2050-01-01'
      this.quitList.id == "";
      this.timeOut = "";
      this.postponeCardShow = false;
    },

    // 点击挂失解挂
    LossCard() {
      console.log(this.selectKey)
      this.selectKey = this.deselectName
      this.handleOkG()
      this.lossCardShow = true;
    },
    //挂失、解挂的确认和取消
    lossCardOk() {
      if (this.selectKey == "") {
        this.$message.error("请选择人员信息");
        return;
      }
      if (this.forminitialE.cardId == "") {
        this.$message.error("请选择挂失/解挂卡片记录");
        return;
      }
      lossCard(this.forminitialE)
        .then((res) => {
          if (res.data.success == false) {
            this.$message.error(res.data.msg);
          }
          if (res.data.success == true) {
            this.getCartOperaList(this.forminitialb)
            this.$message.success("操作成功");
          }
        })
        .catch((err) => {
          this.$message.error("操作失败");
        });
      this.lossCardShow = false;
    },
    lossCardCancel() {
      this.lossCardShow = false;
      this.selectKey = this.deselectName
    },
    // 时间选择
    dataOpenChange(value, mode) {
      console.log(mode);
      this.existsCardparameter.indate = mode;
    },
    // 补卡发卡，选择是否是主卡
    cardholderType(value) {
      if (value == 0) {
        this.existsCardparameter.isMain = 1;
      } else {
        this.existsCardparameter.isMain = 0;
      }
      this.existsCardparameter.currHolder = value
    },
    // 发卡确认
    sendCardOk() {
      // 验证是否可以发卡
      this.existsCardparameter.id = 0;
      this.existsCardparameter.status = 1;
      this.existsCardparameter.staffOrStudInfoId = this.forminitialb.staffOrStudInfoId;
      if (this.existsCardparameter.cardNo == "") {
        this.$message.error("请输入卡号");
        return;
      }
      if(this.existsCardparameter.indate == '') return this.$message.warning('请选择有效期')
      existsCard(this.existsCardparameter)
        .then((res) => {
          console.log(res);
          if (res.data.success == false) {
            // 不可以发卡
            this.$message.error(res.data.msg);
          }
          if (res.data.success == true) {
            // 可以发卡
            sendCardOrRepair(this.existsCardparameter)
              .then((res) => {
                this.$message.success("发卡成功");
                this.existsCardparameter.indate = '2050-01-01'
                this.getCartOperaList(this.forminitialb);
                this.personInfoB(this.forminitialD)

              })
              .catch((err) => {
                // this.$message.error("发卡失败");
              });
            this.existsCardparameter.cardNo = "";
            this.existsCardparameter.des = "";
            this.sendCardShow = false;

            this.cardHolder = '本人'
          }
        })
        .catch((err) => {
          // this.$message.error("操作失败");
        });
        this.defalutDate = null
      // this.sendCardShow = false
    },
    // 发卡取消
    sendCardCancel() {
      this.existsCardparameter.cardNo = "";
      this.existsCardparameter.deposit = "";
      this.existsCardparameter.indate = '2050-01-01'
      this.defdata = this.$moment('2050-01-01','YYYY-MM-DD')
      this.existsCardparameter.des = "";
      this.sendCardShow = false;
      this.cardHolder = '本人'
      this.existsCardparameter.currHolder = 0
      console.log(this.defdata)
    },
    // 发卡
    SendCard() {
      this.sendCardShow = true;
      this.getAlreadyInfoList();
    },
    // 卡号查询
    cardNumSearch() {
      console.log(this.cardNum);
      this.forminitialb.key = this.cardNum;
      this.getCartOperaList(this.forminitialb);
    },
    // 分类：发卡，挂失。。
    selectChange(val) {
      this.forminitialb.doType = val;
      this.getCartOperaList(this.forminitialb);
    },
    // 姓名、卡号、员工关键词
    personInfoSearch() {
      this.forminitial.key = this.staffKey;
      this.forminitial.ymOrgTreeCode = "";
      this.personInfo(this.forminitial);
    },
    argumentSelectA(value, key, extra) {
      this.forminitialD.ymOrgTreeCode = value.ymorgtreecode
      // console.log(value)
      this.personInfoB(this.forminitialD);
    },
    // 选择不同的部门
    argumentSelect(value, key, extra) {
      // this.forminitial.ymOrgTreeCode = data.ymorgtreecode;
      // sessionStorage.setItem("defaultSelect", data.custorgname);
      this.forminitial.ymOrgTreeCode = extra.triggerNode.$attrs.cont.ymorgtreecode
      this.personInfo(this.forminitial);
    },
    // argumentSelect(value, key, extra) {
    //   if (extra.triggerNode) {
    //     //获取当前选中的对象信息
    //     const cont = extra.triggerNode.$attrs.cont;
    //     this.forminitial.ymOrgTreeCode = cont.ymorgtreecode;
    //     // this.formlists.status = cont.status;
    //     this.personInfo(this.forminitial);
    //   }
    // },
    // 部门名称关键字搜索
    onSearch() {
      getPerages({ params: { orgType: 1 } })
        .then((res) => {
          this.departmentList = res.data;
          console.log(res.data[0].custorgname);
        })
        .catch((err) => {
          // this.$message.error("获取部门数据失败");
        });
    },

    // 员工关键字搜索
    staffSearch() {},

    // 获取员工信息列表
    personInfo(params) {
      getPersonInfo({ params: this.forminitial })
        .then((res) => {
          this.$message.success("获取数据成功");
          this.total = res.data.total;
          this.data = res.data.data;
          // this.setDefaultValue(res.data.data[0].orgname)
          // this.$store.commit("setDefaultValue",res.data.data[0].orgname)
        })
        .catch((err) => {
          this.$message.error("获取数据失败");
          console.log(err);
        });
    },
    PagesA(page, pageSize) {
      this.forminitial.limit = pageSize;
      this.forminitial.page = page;
      this.forminitial.start = (page - 1) * pageSize;
      this.personInfo(this.forminitial);
    },
    onShowSizeChangeA(page, limit) {
      this.forminitial.page = page;
      this.forminitial.limit = limit;
      this.personInfo(this.forminitial);
    },
    PagesB(page, pageSize) {
      this.forminitialb.limit = pageSize;
      this.forminitialb.page = page;
      this.forminitialb.start = (page - 1) * pageSize;
      this.getCartOperaList(this.forminitialb);
    },
    onShowSizeChangeB(page, limit) {
      this.forminitialb.page = page;
      this.forminitialb.limit = limit;
      this.getCartOperaList(this.forminitialb);
    },
    getCartOperaList(params) {
      getCartOpera({ params })
        .then((res) => {
          let data = res.data.data;
          console.log(data);
          this.totalB = res.data.total;
          data.forEach((item) => {
            if (item.dotype == 0) {
              item.dotype = "发卡";
            }
            if (item.dotype == 1) {
              item.dotype = "充值";
            }
            if (item.dotype == 2) {
              item.dotype = "退款";
            }
            if (item.dotype == 3) {
              item.dotype = "挂失";
            }
            if (item.dotype == 4) {
              item.dotype = "解挂";
            }
            if (item.dotype == 5) {
              item.dotype = "退卡";
            }
            if (item.dotype == 6) {
              item.dotype = "校正";
            }
            if (item.dotype == 7) {
              item.dotype = "擦除";
            }
            if (item.dotype == 8) {
              item.dotype = "作废";
            }
            if (item.dotype == 9) {
              item.dotype = "过期";
            }
            if (item.dotype == 10) {
              item.dotype = "退职卡费";
            }
            if (item.dotype == 11) {
              item.dotype = "延期";
            }
            item.createdate = this.$moment(item.createdate).format(
              "YYYY/MM/DD hh:mm:ss"
            );
            if (item.currholder == 0) {
              item.currholder = "本人";
            }
            if (item.currholder == 1) {
              item.currholder = "父亲";
            }
            if (item.currholder == 2) {
              item.currholder = "母亲";
            }
            if (item.currholder == 3) {
              item.currholder = "朋友";
            }
            if (item.currholder == 4) {
              item.currholder = "兄妹";
            }
            if (item.currholder == 5) {
              item.currholder = "其他关系";
            }
          });

          this.dataB = data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    moreInfo(text, tags, i) {
      console.log(tags);
      this.staffOrStudInfoIdD = tags.id
      this.deselectName = tags.stafforstuname
      this.itemInfo = tags;
      this.forminitialb.staffOrStudInfoId = tags.id;
      this.$refs.changed.drawer = true;
      this.getCartOperaList(this.forminitialb);
    },
  },
  computed: {},
};
</script>

<style lang="scss">
.select {
  width: 150px;
  padding-left: 10px;
  height: 25px;
  margin-bottom: 20px;
  border: 1px solid #d9d9d9;
}
.tableInput {
  border: 1px solid #d9d9d9;
  outline: none; // 去除选中状态边框
  border-radius: 3px;
  height: 30px;
  width: 300px;
  padding-left: 10px;
}
.tableInput::-webkit-input-placeholder {
  color: #d9d9d9;
}
.tableInput::-moz-placeholder {
  /* Mozilla Firefox 19+ */
  color: #d9d9d9;
}
.tableInput::-moz-placeholder {
  /* Mozilla Firefox 4 to 18 */
  color: #d9d9d9;
}
.tableInput::-moz-placeholder {
  /* Mozilla Firefox 4 to 18 */
  color: #d9d9d9;
}
</style>
